/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.core;

import org.osgi.framework.Bundle;
import org.springframework.osgi.extender.internal.dependencies.startup.ContextState;

import com.cqcis.uip.base.framework.utils.StringUtil;

/**
 * 服务状态
 * 
 * @author huangmy
 * @date 2008-3-21
 */
public class ServiceState {
	private long bundleId; // OSGI bundle ID
	private ContextState state = ContextState.INITIALIZED; // 状态
	private String bundleName; // bundle 名称
	private String message; // 信息描述
	private Throwable throwable;
	private ClassLoader classLoader; // loader
	private UnsatisfiedDependenciesDetector unsatisfiedDependencies; // 目前尚未满足的依赖
	private Bundle bundle;

	public ServiceState(Bundle bundle, UnsatisfiedDependenciesDetector unsatisfiedDependencies) {
		this.bundleId = bundle.getBundleId();
		this.bundleName = bundle.getSymbolicName();
		this.bundle = bundle;
		this.unsatisfiedDependencies = unsatisfiedDependencies;
	}
	
	public long getBundleId() {
		return bundleId;
	}

	public void setBundleId(long bundleId) {
		this.bundleId = bundleId;
	}

	public ContextState getState() {
		return state;
	}

	public void setState(ContextState state) {
		this.state = state;
	}

	public String getBundleName() {
		if (!StringUtil.hasText(bundleName)) {
			return this.bundle.getLocation();
		}
		return bundleName;
	}

	public void setBundleName(String bundleName) {
		this.bundleName = bundleName;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Throwable getThrowable() {
		return throwable;
	}

	public void setThrowable(Throwable throwable) {
		this.throwable = throwable;
	}

	public UnsatisfiedDependenciesDetector getUnsatisfiedDependencies() {
		return unsatisfiedDependencies;
	}

	public ClassLoader getClassLoader() {
		return classLoader;
	}

	public void setClassLoader(ClassLoader classLoader) {
		this.classLoader = classLoader;
	}
}
